using System;
using System.Linq;
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using UnityEditor;
using UnityEngine;

public class CustomMenuItem<T> : OdinMenuItem
{
    private readonly T instance;

    public CustomMenuItem(OdinMenuTree tree, string name,  T instance) : base(tree, name, instance)
    {
        this.instance = instance;
    }

    protected override void OnDrawMenuItem(Rect rect, Rect labelRect)
    {
        labelRect.x -= 16;
        // this.instance.Enabled = GUI.Toggle(labelRect.AlignMiddle(18).AlignLeft(16), this.instance.Enabled, GUIContent.none);

        // Toggle selection when pressing space.
        var selection = this.MenuTree.Selection
            .Select(x => x.Value)
            .OfType<T>();
        if (selection.Contains(this.instance))
        {
            EditorGUI.DrawRect(rect, this.Style.SelectedColorLightSkin);
        }
        else
        {
            // EditorGUI.DrawRect(rect, this.Style.SelectedColorDarkSkin);
        }
    }

    public override string SmartName { get { return this.Name; } }
}